home *** CD-ROM | disk | FTP | other *** search
/ PD ROM 1 / PD ROM Volume I - Macintosh Software from BMUG (1988).iso / Programming / Complete Applications / Othello C Source / info.c < prev    next >
Encoding:
C/C++ Source or Header  |  1985-06-16  |  3.0 KB  |  124 lines  |  [TEXT/ttxt]

  1. /* info.c - display, UpdateInfo */
  2.  
  3. #include "mac/quickdraw.h"
  4. #include "mac/osintf.h"
  5. #include "mac/toolintf.h"
  6. #include "othello.h"
  7.  
  8. #define  CLICKMESSAGEID 2    /* Resource ID of "click to continue" */
  9.  
  10. short inforect[] = { SCALE/2, SCALE * (BOARDSIZE + 1), 512, 512 };
  11. #define InfoRect    (* (Rect *) inforect)
  12. #define GotoLine(l, p)    MoveTo(InfoRect.left+(p), InfoRect.top+(l)*LINEHEIGHT)
  13. #define CENTER    ((412 - SCALE*(BOARDSIZE + 1)) / 2)
  14. #define COLUMN1    (CENTER - (412 - SCALE*(BOARDSIZE + 1)) / 4)
  15. #define COLUMN2    (CENTER + (412 - SCALE*(BOARDSIZE + 1)) / 4)
  16.  
  17. #define BCENTER    (SCALE * (BOARDSIZE + 1) / 2)
  18. #define BBOTTOM    (SCALE*(BOARDSIZE + 1) + LINEHEIGHT)
  19. short messrect[] = { BBOTTOM-LINEHEIGHT, 0, BBOTTOM, BCENTER*2 };
  20. #define MessRect    (* (Rect *) messrect)
  21.  
  22. char message[80] = "";
  23. char note1[80] = "";
  24. char note2[80] = "";
  25. char note3[80] = "";
  26.  
  27. extern int nClicks;
  28.  
  29.  
  30. ClearMessages()
  31. {
  32.     strcpy(message, "");
  33.     strcpy(note1, "");
  34.     strcpy(note2, "");
  35.     strcpy(note3, "");
  36. }
  37.  
  38.  
  39.  
  40. display(t)    /* used to display info for t ticks for debugging */
  41. int    t;
  42. {
  43.     int    ticks;
  44.     
  45.     UpdateInfo();
  46.     ticks = TickCount() + t;
  47.     while (TickCount() < ticks)
  48.         ;
  49. }
  50.  
  51.  
  52.  
  53. UpdateInfo()
  54. {
  55.     GrafPtr saveport;
  56.  
  57. /*    BeginUpdate(myWindow); */
  58.     GetPort(&saveport);
  59.     SetPort(myWindow);
  60.     DrawInfo();
  61.     SetPort(saveport);
  62. /*    EndUpdate(myWindow); */
  63. }
  64.  
  65.  
  66.  
  67. DrawInfo()
  68. {
  69.     char buf[512];
  70.     MoveList moves;
  71.     int nMoves;
  72.     char *clickmessage;
  73.  
  74.     TextFont(InfoFont);
  75.     TextSize(InfoSize);
  76.     EraseRect(&InfoRect);
  77.     EraseRect(&MessRect);
  78.     GotoLine(1, CENTER - StringWidth(message)/2);
  79.     DrawString(message);
  80.     if (GameOver)
  81.         strcpy(buf, "The game is over.");
  82.     else
  83.         sprintf(buf, "%s's move", colorName[curColor]);
  84.     GotoLine(2, CENTER - StringWidth(buf)/2);
  85.     DrawString(buf);
  86.     TextFace(boldStyle);
  87.     GotoLine(4, COLUMN1 - StringWidth("White")/2);
  88.     DrawString("White");
  89.     GotoLine(4, COLUMN2 - StringWidth("Black")/2);
  90.     DrawString("Black");
  91.     TextFace(italicStyle);
  92.     GotoLine(5, COLUMN1 - StringWidth(playerName[player[stoneWhite]])/2);
  93.     DrawString(playerName[player[stoneWhite]]);
  94.     GotoLine(5, COLUMN2 - StringWidth(playerName[player[stoneBlack]])/2);
  95.     DrawString(playerName[player[stoneBlack]]);
  96.     TextFace(0);
  97.     sprintf(buf, "%d", nStones[stoneWhite]);
  98.     GotoLine(6, COLUMN1 - StringWidth(buf)/2);
  99.     DrawString(buf);
  100.     sprintf(buf, "%d", nStones[stoneBlack]);
  101.     GotoLine(6, COLUMN2 - StringWidth(buf)/2);
  102.     DrawString(buf);
  103.     nMoves = FindMoves(curColor, GameBoard, moves, ALL);
  104.     sprintf(buf, "%d choice%s", nMoves, nMoves == 1? "" : "s");
  105.     GotoLine(8, CENTER - StringWidth(buf)/2);
  106.     DrawString(buf);
  107.     sprintf(buf, "Skill level %d", skill);
  108.     GotoLine(9, CENTER - StringWidth(buf)/2);
  109.     DrawString(buf);
  110.     GotoLine(11, CENTER - StringWidth(note1)/2);
  111.     DrawString(note1);
  112.     GotoLine(12, CENTER - StringWidth(note2)/2);
  113.     DrawString(note2);
  114.     GotoLine(13, CENTER - StringWidth(note3)/2);
  115.     DrawString(note3);
  116.     
  117.     if (player[curColor] == Macintosh && nClicks == 0 && !GameOver) {
  118.         TextFont(ChicagoFont);
  119.         clickmessage = isapstr(*GetString(CLICKMESSAGEID));
  120.         MoveTo(BCENTER - StringWidth(clickmessage)/2, BBOTTOM);
  121.         DrawString(clickmessage);
  122.     }
  123. }
  124.